package com.lianbang.pharmacy.adapter

import android.widget.ImageView
import android.widget.LinearLayout
import cn.ubest.mvvmcore.utils.GlideUtils
import cn.ubest.mvvmcore.utils.ResourcesUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.bean.SupplierListBean
import java.text.DecimalFormat

/**
 * Created by maoqi on 2020/11/22.
 */
class SupplierListAdapter
    : BaseQuickAdapter<SupplierListBean, BaseViewHolder>(R.layout.item_supplier_list) {
    override fun convert(helper: BaseViewHolder, item: SupplierListBean) {
        val llStar = helper.getView<LinearLayout>(R.id.ll_star)
        llStar.removeAllViews()
        for (x in 1..item.star_level) {
            val v = ImageView(context)
            v.setImageResource(R.drawable.search_medicine_star)
            v.setPadding(0, 0, ResourcesUtils.getDimens(R.dimen.dp_5), 0)
            llStar.addView(v)
        }
        val df2 = DecimalFormat("#.0")
        helper.setText(R.id.tv_score, df2.format(item.star_level))
            .setText(R.id.tv_title, item.merchant_name)
        GlideUtils.display(context, item.image_cover, helper.getView<ImageView>(R.id.iv_img))
    }

}